package com.changgou.goods.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice //声明该类是一个增强类
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        String message = e.getMessage();
        if (message == null || message.length() == 0) {
            return new Result(false, StatusCode.ERROR, "当前系统繁忙,请您稍后重试");
        }else {
            return new Result(false, StatusCode.ERROR, message);
        }
    }
}
